package com.xuecheng.content.controller;

import com.xuecheng.api.content.model.TeachPlanApi;
import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.api.content.model.qo.BindTeachplanMediaVO;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.EntityMapperTeachPlan;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class TeachplanController implements TeachPlanApi {

    @Autowired
    private TeachplanService  teachplanService;

    /**
     * 课程计划查询树结构
     * @param courseId
     * @return
     */
    @Override
    @GetMapping("teachplan/{courseId}/tree-nodes")
    public TeachplanDTO selectTeachTreeNodes(@PathVariable Long courseId) {

        Long companyId = SecurityUtil.getCompanyId();

        return teachplanService.selectTeachPlanTreeNodes(courseId,companyId);
    }




    /**
     * 新增和修改课程计划
     * @param vo
     * @return
     */
    @PostMapping("teachplan")
    public TeachplanDTO createOrUpdateTeachPlan(@RequestBody TeachplanVO vo) {

        TeachplanDTO teachplanDTO = EntityMapperTeachPlan.INSTANCE.TeachplanVoToTeachplanDto(vo);

        Long companyId = SecurityUtil.getCompanyId();

        return teachplanService.createOrUpdateTeachPlan(teachplanDTO, companyId);
    }

    /**
     * 删除课程计划
     * @param teachplanId
     */
    @DeleteMapping("teachplan/{teachplanId}")
    public void deleteTeachPlan(@PathVariable("teachplanId") Long teachplanId) {
        Long companyId = SecurityUtil.getCompanyId();

        teachplanService.deleteTeachPlan(teachplanId,companyId);
    }

}
